package com.woniu.Service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.Service.OrderService;
import com.woniu.mapper.FlowerOrderMapper;
import com.woniu.vo.OrderVo;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @Author: Gwj
 * @Date: 2024/7/9 11:58
 */
@Service
@Transactional
public class OrderServiceImpl implements OrderService {
    @Resource
    private FlowerOrderMapper flowerOrderMapper;

    /**
     * 分页查询所有订单
     *
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    @Cacheable(value = "order", key = "#root.methodName+#root.args[0]+#root.args[1]")
    public PageInfo<OrderVo> findAllOrderByPage(int pageNum, int pageSize) throws Exception {
        Page<OrderVo> page = PageHelper.startPage(pageNum, pageSize);
        flowerOrderMapper.selectAllOrder();
        return page.toPageInfo();
    }

    /**
     * 条件查询 并且分页
     *
     * @param orderVo
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<OrderVo> findOrdersByConditions(OrderVo orderVo, int pageNum, int pageSize) throws Exception {
        Page<OrderVo> page = PageHelper.startPage(pageNum, pageSize);
        flowerOrderMapper.selectOrderByConditions(orderVo);
        return page.toPageInfo();
    }
}
